{include file="header.html"}
<div id="main">
	{include file="menus.html"}
	<div id="rightCon" class="clearfix layui-body">
		<div class="scroller">
			<div class="search-form clearfix">
				<form method="get" id="formSearch">
					<div class="webkit-box box-align-center">
						<input type="hidden" name="r" value="report/index" />
						<select class="querySelect" name="field">
							{html_options options=$search_options selected=$smarty.get.field}
						</select>
						<input class="infoTableInput mr10" type="text" name="search_name"
							value="{$smarty.get.search_name|escape}" />
						{$lang.status}
						<select name="status" class="querySelect">
							<option value="-1" {if !in_array($smarty.get.status, array(0,1))} selected="selected" {/if}>
								不限制
							</option>
							<option value="0" {if $smarty.get.status eq '0' } selected="selected" {/if}>未处理</option>
							<option value="1" {if $smarty.get.status eq '1' } selected="selected" {/if}>已处理</option>
						</select>
						<input type="submit" class="layui-btn layui-bg-blue layui-btn-sm block width7"
							value="{$lang.query}" />
						<!--{if $filtered}-->
						<a class="layui-btn layui-btn-primary layui-btn-sm box-align-center"
							href="{url route='report/index'}">{$lang.cancel_query}</a>
						<!--{/if}-->
					</div>
				</form>
			</div>
			<div class="tablegrid">
				<table class="layui-hide" id="tablegrid" lay-filter="tablegrid"></table>
			</div>
			{include file="version.html"}
		</div>
	</div>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-bg-blue" lay-event="batverify"><i class="layui-icon layui-icon-edit"></i>批量审核</button>
		<button class="layui-btn layui-btn-primary layui-border-blue" lay-event="batdel"><i class="layui-icon layui-icon-close"></i>批量删除</button>
	</div>
</script>

<script type="text/html" id="colBar">
	<a class="ml5 mr5 blue pointer" lay-event="goods">查看商品</a>
	<a class="ml5 mr5 blue pointer" lay-event="store">查看店铺</a>
</script>
<script>
	layui.use('table', function () {
		var table = layui.table;

		table.render({
			elem: '#tablegrid'
			//,skin: 'line'
			, url: url(['report/index', $("#formSearch").serializeJson()])
			, toolbar: '#toolbar'
			, defaultToolbar: ['filter', /*'exports',*/ 'print']
			, title: '举报管理'
			//, size: 'lg'
			, cols: [[
				{ type: 'checkbox', fixed: 'left' }
				, { field: 'id', title: 'ID', width: 70, fixed: 'left', unresize: true, sort: true }
				, { field: 'username', title: '举报人', width: 100 }
				, { field: 'content', title: '举报内容', width: 300, sort: true }
				, { field: 'add_time', title: '举报时间', width: 170, sort: true }
				, { field: 'goods_name', title: '被举报的商品', width: 300, sort: true }
				, { field: 'store_name', title: '被举报的店铺', width: 200, sort: true }
				, {
					field: 'status', title: '处理状态', width: 160, sort: true, templet: function (res) {
						return res.status == 1 ? '<em class="green"><i class="fa fa-check-circle"></i>已处理</em>' : '<em class="gray"><i class="fa fa-ban"></i>未处理</em>'
					}
				}
				, { fixed: 'right', title: '操作', toolbar: '#colBar', width: 190, align: 'center' }
			]]
			, page: {
				theme: 'blue'
			}
		});

		//监听头工具栏事件
		table.on('toolbar(tablegrid)', function (obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			if (checkStatus.data.length <= 0) {
				return false;
			}
			var items = new Array();
			$.each(checkStatus.data, function (i, item) {
				items.push(item.id);
			});
			if (obj.event === 'batdel') {
				var btnObj = $('[lay-event="' + obj.event + '"]');
				btnObj.attr('confirm', '删除后将不能恢复，确认删除这 ' + items.length + ' 项吗？');
				ajaxRequest(btnObj, url(['report/delete', { id: items.join(',') }]), function () {
					table.reload('tablegrid');
				});
			}
			else if (obj.event === 'batverify') {
				return verify(items.join(','), table);
			}
		});

		//监听行工具事件
		table.on('tool(tablegrid)', function (obj) {
			var data = obj.data;

			if (obj.event === 'goods') {
				window.open(url(['goods/index', { id: data.goods_id }, HOME_URL]));
			}
			else if (obj.event === 'store') {
				window.location.href = url(['store/edit', { id: data.store_id }]);
			}
		});
	});

	function verify(id, table) {
		layer.prompt({
			formType: 2,
			value: '',
			title: lang.verify_content
		}, function (value, index, elem) {
			$.ajax({
				type: "GET",
				dataType: "json",
				url: url(['report/verify', { id: id, verify: value }]),
				success: function (data) {
					if (data.done) {
						layer.open({ content: lang.verify_ok });
						layer.close(index);
						table.reload('tablegrid');
					} else {
						layer.msg(data.msg);
					}
				},
				error: function (data) {
					layer.msg(data.msg);
				}
			});
			layer.close(index);
		});
	}
</script>
{include file="footer.html"}